package com.tf.integrated.controller;

import com.ccssoft.m8.common.web.BaseController;
import com.tf.integrated.config.Config;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.FileInputStream;
/**
 * 图片管理接口
 * @author allen
 * @date: 2020年9月14日上午10:56:20
 */
@Api(value = "图片管理接口",description="ImagesController")
@RestController
@RequestMapping("/dataimages")
public class ImagesController extends BaseController
{
    @ApiOperation("获取图片展示链接")
    @GetMapping(value = "/{imapath}",produces = MediaType.IMAGE_JPEG_VALUE)
    @CrossOrigin(origins = "*",maxAge = 86400)
    public byte[] dataimages(@PathVariable("imapath") String imapath)
    {
        try
        {
            String  tmppath = Config.getMimgpath() + imapath + ".jpg";
            //logger.error("dataimages==="+tmppath);
            File file = new File(tmppath);
            if (!file.exists())
            {
               return null;
            }
            FileInputStream inputStream = new FileInputStream(file);
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes, 0, inputStream.available());
            return bytes;
        }
        catch (Exception e)
        {

        }
        return null;
    }
}